import java.util.Arrays;

public class CommandLine {
    public static void main (String[] args) {
//        System.out.println("Answer: " + numberChars ('о', "колбаса" ));
//        System.out.println("Answer: " + numberChars ('ы', "колбаса" ));
        //('а', 'колбаса') → 2
//        ('о', 'колбаса') → 1
//        ('ы', 'колбаса') → 0
//        System.out.println("Answer: " + factorial(0));
//        System.out.println("Answer: " + factorial(1));
//        System.out.println("Answer: " + factorial(4));

        System.out.println("Answer: " + anagramma ("kkkk","kkk"));
        System.out.println("Answer: " + anagramma ("жуткая","утяжка"));
    }

        public static int numberChars (char a, String word) {
            char [] wordArray = word.toLowerCase().toCharArray();
            int counter = 0;

            for (int i=0; i<wordArray.length; i++) {
                if (wordArray[i] == a) {
                    counter = counter + 1;
                }
                }
            return counter;
            }



        public static int factorial (int number) {
        int currentFactorial = number;

                if (number>1) {
                    currentFactorial = currentFactorial * factorial (number-1);
                }
                if (number == 0) {
                    currentFactorial = 1;
                }
                return currentFactorial;
//        0! = 1
//                1! = 1
//                4! = 24
        }


        public static boolean anagramma (String word1, String word2)
        {
            String sortedString1 = sortedString (word1);
            String sortedString2 = sortedString (word2);

            if (sortedString1.equals(sortedString2)) {
             return true;
            }
            else return false;
        }

        public static String sortedString (String inputString) {
            char [] charArray = inputString.toCharArray();
            char temp;
            for (int i=0; i<charArray.length; i++) {
                for (int j=0; j<charArray.length - 1;j++) {
                    if (charArray[j]>charArray[j+1]) {
                        temp = charArray[j+1];
                        charArray[j+1] = charArray [j];
                        charArray [j] = temp;

                    }
                }
            }
            String sortedString = String.copyValueOf(charArray);
            return sortedString;
        }
//    жуткая, утяжка true
//    каноннада, анакконда false
//    канонада, анаконда true
//    стол, стул false
//    кккк, ккк false



}
